package com.zzz.dynamicds.config;

import com.zzz.dynamicds.bean.DBContextHolder;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class DataSourceAop {

    @Pointcut("@annotation(com.zzz.dynamicds.annotation.Slave)")
    public void slave() {

    }

    @Pointcut("@annotation(com.zzz.dynamicds.annotation.Master)")
    public void master() {

    }

    @Before("slave()")
    public void read() {
        DBContextHolder.slave();
    }

    @Before("master()")
    public void write() {
        DBContextHolder.master();
    }

}